﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.IO;

public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Login_Click(object sender, EventArgs e)
    {
        error.Text = "";
        RE_GenericBean usuario = null;
        try
        {
            usuario = DB.Autenticar(txt1.Text);
            if (usuario != null)
            {
                if (usuario.strC1 == txt1.Text.ToUpper() && usuario.strC2 == txt2.Text.ToUpper())
                {
                    Session["user"] = usuario;
                    Response.Redirect("megahealth//Default.aspx");
                }
                else
                {
                    txt1.Text = ""; txt2.Text = "";
                    error.Text = "Login failed, username or password incorrect!";
                    txt1.Focus();
                }
            }
            else
            {
                if (txt1.Text == "" && txt2.Text == "")
                {
                    txt1.Focus();
                }
                else
                {
                    txt1.Text = ""; txt2.Text = "";
                    error.Text = "Login failed, username or password incorrect!";
                    txt1.Focus();
                }
            }
        }
        catch (Exception ex)
        {
            Utility.writeError("Fallo de la autenticacion!");
            Utility.writeError(DateTime.Now.ToString() + " " + ex.Message.ToString() + " " + ex.StackTrace);
        }
    }
}